package com.eco.fanliapp.job.sytimeperiodgoodsjob;

import com.eco.fanliapp.service.IJobSQKBTimeLimitSecondKillService;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;

/**
 * @author lc
 * @Title: JobSQKBTimeLimitBuyNum
 * @ProjectName shengyaapp
 * @Description: 更新秒杀商品购买数量
 * @date 2018/8/217:14
 */
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class JobSQKBTimeLimitBuyNum implements Job,Serializable {

    private static final Logger logger = LoggerFactory.getLogger(JobSQKBTimeLimitBuyNum.class);

    @Autowired
    private IJobSQKBTimeLimitSecondKillService jobSQKBTimeLimitSecondKillService;

    public JobSQKBTimeLimitBuyNum() {
    }

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        //取得job详情
        JobDetail jobDetail = context.getJobDetail();

        JobDataMap dataMap =  jobDetail.getJobDataMap();

        int executeCount = 0;
        if (dataMap.containsKey("runCount")) {
            executeCount = dataMap.getInt("runCount");
        }

        // 增量计数并将其存储回 JobDataMap，这样可以适当保持工作状态
        executeCount++;
        dataMap.put("runCount", executeCount);

        long startTime = System.currentTimeMillis();
        logger.info("***************************************开始执行定时任务-更新秒杀商品购买数量-JobSQKBTimeLimitBuyNum：executeCount="+executeCount+"--startTime="+startTime);

        jobSQKBTimeLimitSecondKillService.getSQKBData(true);

        long endTime = System.currentTimeMillis();
        logger.info("***************************************结束执行定时任务-更新秒杀商品购买数量-JobSQKBTimeLimitBuyNum：executeCount="+executeCount+"--endTime="+endTime+"--耗时="+(endTime-startTime));
    }

}
